﻿using BCDto.Sim.Admin.AdminPermissionRecord;
using BCService.Sim.Admin.DepartmentPermissionRecord;
using BCService.Sim.Company.Department;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Net;

namespace BCTMSRESTful.Controllers.Management.Admin.AdminPermission
{
    /// <summary>
    /// 部门权限
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class DepartmentPermissionRecordController : ManagementBaseController
    {
        private readonly IDepartmentPermissionRecordService departmentPermissionRecordService;

        public DepartmentPermissionRecordController(IDepartmentPermissionRecordService departmentPermissionRecordService)
        {
            this.departmentPermissionRecordService = departmentPermissionRecordService;
        }

        #region 添加部门权限记录
        /// <summary>
        /// 添加部门权限记录
        /// </summary>
        /// <param name="requestDto">部门权限</param>
        /// <response code="201">创建员工权限信息</response>
        /// <returns></returns>
        [HttpPost("[action]")]
        [Log("添加部门权限记录")]
        [ProducesResponseType(typeof(AdminPermissionRecordDto), 200)]
        public IActionResult Setting([FromBody] DepartmentPermissionRecordRequestDto requestDto)
        {
            var result = this.departmentPermissionRecordService.Setting(requestDto);
            return StatusCode((int)HttpStatusCode.Created, result);
        }
        #endregion
        
        #region 获取部门权限记录列表
        /// <summary>
        /// 获取部门权限记录列表
        /// </summary>
        /// <param name="departmentId">部门Id</param>   
        /// <response code="200">获取部门权限记录列表成功。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(List<AdminPermissionRecordDto>), 200)]
        public IActionResult List([FromQuery(Name = "department_id")]int departmentId)
        {
            var list = this.departmentPermissionRecordService.GetList(departmentId);
            return this.Ok(list);
        }
        #endregion

        #region 删除部门权限

        /// <summary>
        /// 删除指定部门权限
        /// </summary>
        /// <response code="204">删除成功</response>
        /// <returns></returns>
        [HttpDelete("{department_id}/{operation_permission}")]
        [Log("删除部门权限")]
        public IActionResult Delete([FromRoute(Name = "department_id")]int departmentId, [FromRoute(Name = "operation_permission")]string operationPermission)
        {
            this.departmentPermissionRecordService.DeleteDepartmentPermission(this.Admin, departmentId, operationPermission);
            return this.NoContent();
        }
        #endregion
    }
}